define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
    var button = '';//html button组
    var events = '';//修改button

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'crm/buserfolloe/index/',
                    add_url: 'crm/buserfolloe/add',
                    edit_url: 'crm/buserfolloe/edit',
                    del_url: 'crm/buserfolloe/del',
                    multi_url: 'crm/buserfolloe/multi',
                    table: 'buserfollow',
                },
                queryParams: function (params) {
                    // 自定义搜索条件
                    var filter = params.filter ? JSON.parse(params.filter) : {};
                    var op = params.op ? JSON.parse(params.op) : {};
                    //filter.后跟的是在ajax里使用的名称
                    if($('#admin_id').val()){
                        params['wf_admin_id'] = $('#admin_id').val();
                    }else  if($('#group').val()){
                        params['wf_admin_id'] = '';
                        params['wf_group_id'] = $('#group').val();
                    }
                    params.filter = JSON.stringify(filter);
                    params.op = JSON.stringify(op);
                    return params;
                }
            });
            var table = $("#table");
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                searchFormVisible: true,
                searchFormTemplate: 'customformtpl',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'buser.username', title: __('Buser.username'),operate:'LIKE'},
                        {field: 'buser.contacts', title: __('Buser.contacts'),operate:'LIKE'},
                        {field: 'product.product', title: __('Product.product'),operate:'LIKE'},
                        {field: 'buser.qq', title: __('Buser.qq'),operate:'LIKE'},
                        {field: 'buser.wechat', title: __('Buser.wechat'),operate:'LIKE'},
                        {field: 'buser.mobile', title: __('Buser.mobile'),operate:'LIKE'},
                        {field: 'buser.email', title: __('Buser.email'),operate:'LIKE'},
                        {field: 'instructions', title: __('Instructions'),operate:false},
                        {field: 'sectionlist', title: __('Sectionlist'), searchList: {"0":__('Sectionlist 0'),"1":__('Sectionlist 1'),"2":__('Sectionlist 2'),"3":__('Sectionlist 3'),"4":__('Sectionlist 4'),"5":__('Sectionlist 5'),"6":__('Sectionlist 6')}, formatter: Table.api.formatter.normal},
                        {field: 'currentlist', title: __('Currentlist'), searchList: {"0":__('Currentlist 0'),"1":__('Currentlist 1'),"2":__('Currentlist 2'),"3":__('Currentlist 3'),"4":__('Currentlist 4'),"5":__('Currentlist 5'),"6":__('Currentlist 6')}, formatter: Table.api.formatter.normal},
                        {field: 'admin.nickname', title: __('Admin.nickname'),operate:false},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                       /* {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                            formatter: function (value, row, index) {
                                var that = $.extend({}, this);
                                var table = $(that.table).clone(true);
                                //审核过的数据和不是销售人员隐藏编辑按钮
                                $(table).data("operate-edit", null);
                                $(table).data("operate-del", null);
                                that.table = table;
                                return Table.api.formatter.operate.call(that, value, row, index);
                            }
                        },*/
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
            Form.api.bindevent($("form#cxselectform"));
        },
        add: function () {
            Controller.api.bindevent();
            $('#c-sectionlist').bind('change',function () {
                if($('#c-sectionlist').val()==6){
                    $('#cooperation').show();
                }else {
                    $('#cooperation').hide();
                }
            })
        },
        edit: function () {
            Controller.api.bindevent();
        },
        examine:function(){
            Controller.api.bindevent();
        },
        /*金融类跟进数据*/
        bk_record: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'crm/buserfolloe/bk_record/',
                    table: 'buserfollow',
                },
                queryParams: function (params) {
                    // 自定义搜索条件
                    var filter = params.filter ? JSON.parse(params.filter) : {};
                    var op = params.op ? JSON.parse(params.op) : {};
                    //filter.后跟的是在ajax里使用的名称
                    if($('#admin_id').val()){
                        params['wf_admin_id'] = $('#admin_id').val();
                    }else  if($('#group').val()){
                        params['wf_admin_id'] = '';
                        params['wf_group_id'] = $('#group').val();
                    }
                    params.filter = JSON.stringify(filter);
                    params.op = JSON.stringify(op);
                    return params;
                }
            });
            var table = $("#table");
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                searchFormVisible: true,
                searchFormTemplate: 'customformtpl',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'bkuser.company', title: __('Bkuser.company'),operate:'LIKE'},
                        {field: 'bkuser.username', title: __('Bkuser.username'),operate:'LIKE'},
                        {field: 'product.product', title: __('Product.product'),operate:'LIKE'},
                        {field: 'instructions', title: __('Instructions'),operate:false},
                        {field: 'sectionlist', title: __('Sectionlist'), searchList: {"0":__('Sectionlist 0'),"1":__('Sectionlist 1'),"2":__('Sectionlist 2'),"3":__('Sectionlist 3'),"4":__('Sectionlist 4'),"5":__('Sectionlist 5'),"6":__('Sectionlist 6')}, formatter: Table.api.formatter.normal},
                        {field: 'currentlist', title: __('Currentlist'), searchList: {"0":__('Currentlist 0'),"1":__('Currentlist 1'),"2":__('Currentlist 2'),"3":__('Currentlist 3'),"4":__('Currentlist 4'),"5":__('Currentlist 5'),"6":__('Currentlist 6')}, formatter: Table.api.formatter.normal},
                        {field: 'admin.nickname', title: __('Admin.nickname'),operate:false},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
            Form.api.bindevent($("form#cxselectform"));
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});